// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Hang Glider Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias object.state : player.state
private alias object.ypos : player.ypos
private alias object.xpos : player.xpos
private alias object.xvel : player.xvel
private alias object.yvel : player.yvel
private alias object.speed : player.speed
private alias object.direction : player.direction
private alias object.gravity : player.gravity
private alias object.animation : player.animation
private alias object.collisionTop : player.collisionTop
private alias object.jumpPress : player.jumpPress
private alias object[0].value35 : player.jumpAbilityState
private alias object[currentPlayer].value35 : player.jumpAbilityState


// Static Values

// Tables

event ObjectUpdate
	if object.value0 > 0
		object.value0--
	end if
	if object.value3 == 1
		object.ixpos += object.xvel
		object.iypos += object.yvel
	end if
	if object.value2 == 0
		ObjectTileCollision(CSIDE_LWALL, 0, 0, 0)
		if checkResult == true
			player[currentPlayer].animation = ANI_JUMPING
			PlaySfx(SfxName[Jump], 0)
			player.jumpAbilityState = 1
			player[currentPlayer].state = Player_State_Air
			player[currentPlayer].yvel 		= -0x40000
			player[currentPlayer].gravity 	= 1
			object.value0 = 8
			object.value2 = 1
			player[currentPlayer].yvel += -0x40000
			player[currentPlayer].yvel += -0x40000
		end if
		ObjectTileCollision(CSIDE_FLOOR, 0, 16, 0)
		if checkResult == true
			player[currentPlayer].state = Player_HandleGroundMovement
			player[currentPlayer].gravity = 0
			object.value0 = 8
			object.value2 = 1
		end if
	end if
	if object.outOfBounds == true
		object.xpos = object.value6
		object.ypos = object.value7
		object.value3 = 0
		object.value2 = 0
	end if
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if player[currentPlayer].state != Player_State_Static
			if object.value0 == 0
				temp0 = player[currentPlayer].collisionTop
				BoxCollisionTest(C_TOUCH, object.entityPos, -24, 0, 24, 8, currentPlayer, -1, temp0, 1, temp0)
				if checkResult == true
					object.value6 = object.xpos
					object.value7 = object.ypos
					if player[currentPlayer].gravity == 1
						player[currentPlayer].xpos = object.xpos
						player[currentPlayer].ypos = object.ypos
						player[currentPlayer].direction = FACING_LEFT
						player[currentPlayer].state = Player_State_Static
						player[currentPlayer].animation = ANI_HANGLIDE
						player[currentPlayer].speed = 0
						player[currentPlayer].xvel = 0
						player[currentPlayer].yvel = 0
						player[currentPlayer].ypos = player[currentPlayer].collisionTop
						player[currentPlayer].ypos++
						FlipSign(player[currentPlayer].ypos)
						player[currentPlayer].ypos <<= 16
						player[currentPlayer].ypos += object.ypos
						PlaySfx(SfxName[Catch], 0)
					end if
				end if
			end if
		else
			temp1 = 0
			BoxCollisionTest(C_TOUCH, object.entityPos, -24, -24, 24, 24, currentPlayer, -1, -1, 1, 1)
			if checkResult == true
				object.value3 = 1
				player[currentPlayer].xpos = object.xpos
				player[currentPlayer].ypos = object.ypos
				if player[currentPlayer].jumpPress == true
					player[currentPlayer].animation = ANI_JUMPING
					PlaySfx(SfxName[Jump], 0)
					player.jumpAbilityState = 1
#platform: USE_STANDALONE
					player[currentPlayer].state = Player_State_Air
#endplatform
#platform: USE_ORIGINS
					player[currentPlayer].state = Player_State_Air_NoDropDash
#endplatform
					player[currentPlayer].yvel 		= -0x60000
					player[currentPlayer].gravity 	= 1
					object.value0 = 8
				else
				end if
			end if
		end if
	next
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("EHZ/Objects.gif")
	SpriteFrame(-38, -28, 88, 40, 257, 1)
	foreach (TypeName[Hang Glider], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].xvel = 0x3
		object[arrayPos0].yvel = 0x1
		object[arrayPos0].drawOrder = 3
	next
end event

event RSDKDraw
	DrawSprite(0)
end event 

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
